<template>
	<el-main class="bg edit_wrap comtable_e">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
		<el-row class="row_ce"> 
							<el-col v-if="$check_field('get','enterprise_user') || $check_field('add','enterprise_user') || $check_field('set','enterprise_user')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="企业用户" prop="enterprise_user">
																<el-select v-if="(form['interview_invitation_id'] && $check_field('set','enterprise_user')) || (!form['interview_invitation_id'] && $check_field('add','enterprise_user'))" id="enterprise_user" v-model="form['enterprise_user']" :disabled="disabledObj['enterprise_user_isDisabled']">
							<el-option v-for="o in list_user_enterprise_user" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
						<el-select v-else-if="$check_field('get','enterprise_user')" id="enterprise_user" v-model="form['enterprise_user']" :disabled="true">
							<el-option v-for="o in list_user_enterprise_user" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','name_of_enterprise') || $check_field('add','name_of_enterprise') || $check_field('set','name_of_enterprise')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="企业名称" prop="name_of_enterprise">
															<el-input id="name_of_enterprise" v-model="form['name_of_enterprise']" placeholder="请输入企业名称"
							  v-if="(form['interview_invitation_id'] && $check_field('set','name_of_enterprise')) || (!form['interview_invitation_id'] && $check_field('add','name_of_enterprise'))" :disabled="disabledObj['name_of_enterprise_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','name_of_enterprise')">{{form['name_of_enterprise']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','type_of_enterprise') || $check_field('add','type_of_enterprise') || $check_field('set','type_of_enterprise')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="企业类型" prop="type_of_enterprise">
															<el-input id="type_of_enterprise" v-model="form['type_of_enterprise']" placeholder="请输入企业类型"
							  v-if="(form['interview_invitation_id'] && $check_field('set','type_of_enterprise')) || (!form['interview_invitation_id'] && $check_field('add','type_of_enterprise'))" :disabled="disabledObj['type_of_enterprise_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','type_of_enterprise')">{{form['type_of_enterprise']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','enterprise_address') || $check_field('add','enterprise_address') || $check_field('set','enterprise_address')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="企业地址" prop="enterprise_address">
															<el-input id="enterprise_address" v-model="form['enterprise_address']" placeholder="请输入企业地址"
							  v-if="(form['interview_invitation_id'] && $check_field('set','enterprise_address')) || (!form['interview_invitation_id'] && $check_field('add','enterprise_address'))" :disabled="disabledObj['enterprise_address_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','enterprise_address')">{{form['enterprise_address']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','title_of_recruitment') || $check_field('add','title_of_recruitment') || $check_field('set','title_of_recruitment')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="招聘标题" prop="title_of_recruitment">
															<el-input id="title_of_recruitment" v-model="form['title_of_recruitment']" placeholder="请输入招聘标题"
							  v-if="(form['interview_invitation_id'] && $check_field('set','title_of_recruitment')) || (!form['interview_invitation_id'] && $check_field('add','title_of_recruitment'))" :disabled="disabledObj['title_of_recruitment_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','title_of_recruitment')">{{form['title_of_recruitment']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','post_classification') || $check_field('add','post_classification') || $check_field('set','post_classification')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="岗位分类" prop="post_classification">
															<el-input id="post_classification" v-model="form['post_classification']" placeholder="请输入岗位分类"
							  v-if="(form['interview_invitation_id'] && $check_field('set','post_classification')) || (!form['interview_invitation_id'] && $check_field('add','post_classification'))" :disabled="disabledObj['post_classification_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','post_classification')">{{form['post_classification']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','recruitment_salary') || $check_field('add','recruitment_salary') || $check_field('set','recruitment_salary')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="招聘薪资" prop="recruitment_salary">
															<el-input id="recruitment_salary" v-model="form['recruitment_salary']" placeholder="请输入招聘薪资"
							  v-if="(form['interview_invitation_id'] && $check_field('set','recruitment_salary')) || (!form['interview_invitation_id'] && $check_field('add','recruitment_salary'))" :disabled="disabledObj['recruitment_salary_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','recruitment_salary')">{{form['recruitment_salary']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','recruitment_requirements') || $check_field('add','recruitment_requirements') || $check_field('set','recruitment_requirements')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="招聘要求" prop="recruitment_requirements">
															<el-input id="recruitment_requirements" v-model="form['recruitment_requirements']" placeholder="请输入招聘要求"
							  v-if="(form['interview_invitation_id'] && $check_field('set','recruitment_requirements')) || (!form['interview_invitation_id'] && $check_field('add','recruitment_requirements'))" :disabled="disabledObj['recruitment_requirements_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','recruitment_requirements')">{{form['recruitment_requirements']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','ordinary_user') || $check_field('add','ordinary_user') || $check_field('set','ordinary_user')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="普通用户" prop="ordinary_user">
																<el-select v-if="(form['interview_invitation_id'] && $check_field('set','ordinary_user')) || (!form['interview_invitation_id'] && $check_field('add','ordinary_user'))" id="ordinary_user" v-model="form['ordinary_user']" :disabled="disabledObj['ordinary_user_isDisabled']">
							<el-option v-for="o in list_user_ordinary_user" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
						<el-select v-else-if="$check_field('get','ordinary_user')" id="ordinary_user" v-model="form['ordinary_user']" :disabled="true">
							<el-option v-for="o in list_user_ordinary_user" :key="o['username']" :label="o['nickname'] + '-' + o['username']"
									   :value="o['user_id']">
							</el-option>
						</el-select>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','user_name') || $check_field('add','user_name') || $check_field('set','user_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="用户姓名" prop="user_name">
															<el-input id="user_name" v-model="form['user_name']" placeholder="请输入用户姓名"
							  v-if="(form['interview_invitation_id'] && $check_field('set','user_name')) || (!form['interview_invitation_id'] && $check_field('add','user_name'))" :disabled="disabledObj['user_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','user_name')">{{form['user_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','name_of_college') || $check_field('add','name_of_college') || $check_field('set','name_of_college')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="学院名称" prop="name_of_college">
															<el-input id="name_of_college" v-model="form['name_of_college']" placeholder="请输入学院名称"
							  v-if="(form['interview_invitation_id'] && $check_field('set','name_of_college')) || (!form['interview_invitation_id'] && $check_field('add','name_of_college'))" :disabled="disabledObj['name_of_college_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','name_of_college')">{{form['name_of_college']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','professional_name') || $check_field('add','professional_name') || $check_field('set','professional_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="专业名称" prop="professional_name">
															<el-input id="professional_name" v-model="form['professional_name']" placeholder="请输入专业名称"
							  v-if="(form['interview_invitation_id'] && $check_field('set','professional_name')) || (!form['interview_invitation_id'] && $check_field('add','professional_name'))" :disabled="disabledObj['professional_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','professional_name')">{{form['professional_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','class_name') || $check_field('add','class_name') || $check_field('set','class_name')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="班级名称" prop="class_name">
															<el-input id="class_name" v-model="form['class_name']" placeholder="请输入班级名称"
							  v-if="(form['interview_invitation_id'] && $check_field('set','class_name')) || (!form['interview_invitation_id'] && $check_field('add','class_name'))" :disabled="disabledObj['class_name_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','class_name')">{{form['class_name']}}</div>
											</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','invitation_time') || $check_field('add','invitation_time') || $check_field('set','invitation_time')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="邀请时间" prop="invitation_time">
											<el-date-picker :disabled="disabledObj['invitation_time_isDisabled']" v-if="(form['interview_invitation_id'] && $check_field('set','invitation_time')) || (!form['interview_invitation_id'] && $check_field('add','invitation_time'))" id="invitation_time"
						v-model="form['invitation_time']" type="datetime" placeholder="选择日期时间">
					</el-date-picker>
					<div v-else-if="$check_field('get','invitation_time')">{{form['invitation_time']}}</div>
							</el-form-item>
			</el-col>
								<el-col v-if="$check_field('get','invitation_notes') || $check_field('add','invitation_notes') || $check_field('set','invitation_notes')" :xs="24" :sm="12" :lg="8" class="el_form_item_warp">
							<el-form-item label="邀请备注" prop="invitation_notes">
															<el-input id="invitation_notes" v-model="form['invitation_notes']" placeholder="请输入邀请备注"
							  v-if="(form['interview_invitation_id'] && $check_field('set','invitation_notes')) || (!form['interview_invitation_id'] && $check_field('add','invitation_notes'))" :disabled="disabledObj['invitation_notes_isDisabled']"></el-input>
					<div v-else-if="$check_field('get','invitation_notes')">{{form['invitation_notes']}}</div>
											</el-form-item>
			</el-col>
						
	
	
		
		
						<el-col :xs="24" :sm="12" :lg="8" class="el_form_item_warp" v-if="!form['source_user_id'] && 1 > 0">
			  <el-form-item label="结果限次">
				<el-input id="limit_times" v-model="form['interview_results_limit_times']" placeholder="结果限制次数，0为不限"
						  v-if="$check_option('/interview_invitation/view','can_limits')"
				></el-input>
				<div v-else-if="$check_action('/interview_invitation/view','get')" v-html="form['interview_results_limit_times']"></div>
			  </el-form-item>
			</el-col>
			
	
	
		
		
	
		</el-row>
			<el-col :xs="24" :sm="12" :lg="8" class="el_form_btn_warp">
				<el-form-item v-if="$check_action('/interview_invitation/view','set') || $check_action('/interview_invitation/view','add')">
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
				<el-form-item v-else>
					<el-button @click="cancel()">返回</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
	import mixin from "@/mixins/page.js";
	export default {
		mixins: [mixin],
		data() {
			return {
				field: "interview_invitation_id",
				url_add: "~/api/interview_invitation/add?",
				url_set: "~/api/interview_invitation/set?",
				url_get_obj: "~/api/interview_invitation/get_obj?",
				url_upload: "~/api/interview_invitation/upload?",

				query: {
					"interview_invitation_id": 0,
				},

				form: {
								"enterprise_user": 0, // 企业用户
										"name_of_enterprise":  '', // 企业名称
										"type_of_enterprise":  '', // 企业类型
										"enterprise_address":  '', // 企业地址
										"title_of_recruitment":  '', // 招聘标题
										"post_classification":  '', // 岗位分类
										"recruitment_salary":  '', // 招聘薪资
										"recruitment_requirements":  '', // 招聘要求
										"ordinary_user": 0, // 普通用户
										"user_name":  '', // 用户姓名
										"name_of_college":  '', // 学院名称
										"professional_name":  '', // 专业名称
										"class_name":  '', // 班级名称
										"invitation_time":  '', // 邀请时间
										"invitation_notes":  '', // 邀请备注
											"interview_invitation_id": 0, // ID
													"interview_results_limit_times": 1, // 结果限制次数
												},
				disabledObj:{
								"enterprise_user_isDisabled": false,
										"name_of_enterprise_isDisabled": false,
										"type_of_enterprise_isDisabled": false,
										"enterprise_address_isDisabled": false,
										"title_of_recruitment_isDisabled": false,
										"post_classification_isDisabled": false,
										"recruitment_salary_isDisabled": false,
										"recruitment_requirements_isDisabled": false,
										"ordinary_user_isDisabled": false,
										"user_name_isDisabled": false,
										"name_of_college_isDisabled": false,
										"professional_name_isDisabled": false,
										"class_name_isDisabled": false,
										"invitation_time_isDisabled": false,
										"invitation_notes_isDisabled": false,
										},

	
					// 用户列表
				list_user_enterprise_user: [],
					
			
			
			
			
			
			
			
					// 用户列表
				list_user_ordinary_user: [],
					
			
			
			
			
			
		
			}
		},
		methods: {

	
	
				/**
			 * 获取企业用户用户列表
			 */
			async get_list_user_enterprise_user() {
                var json = await this.$get("~/api/user/get_list?user_group=企业用户");
                if(json.result && json.result.list){
                    this.list_user_enterprise_user = json.result.list;
                }
                else if(json.error){
                    console.error(json.error);
                }
			},
					get_user_enterprise_user(id){
				var obj = this.list_user_enterprise_user.getObj({"user_id":id});
				var ret = "";
				if(obj){
					if(obj.nickname){
						ret = obj.nickname;}
					else{
						ret = obj.username;
					}
				}
				return ret;
			},
			
	
			
	
			
	
			
	
			
	
			
	
			
	
			
	
				/**
			 * 获取普通用户用户列表
			 */
			async get_list_user_ordinary_user() {
                var json = await this.$get("~/api/user/get_list?user_group=普通用户");
                if(json.result && json.result.list){
                    this.list_user_ordinary_user = json.result.list;
                }
                else if(json.error){
                    console.error(json.error);
                }
			},
					get_user_ordinary_user(id){
				var obj = this.list_user_ordinary_user.getObj({"user_id":id});
				var ret = "";
				if(obj){
					if(obj.nickname){
						ret = obj.nickname;}
					else{
						ret = obj.username;
					}
				}
				return ret;
			},
			
	
			
	
			
	
			
	
			
	
			
	
		
			/**
			 * 获取对象之前
			 * @param {Object} param
			 */
			get_obj_before(param) {
				var form = "";
															// 获取缓存数据附加
				form = $.db.get("form");
									$.push(this.form ,form);
											
				if(this.form && form){
					Object.keys(this.form).forEach(key => {
						Object.keys(form).forEach(dbKey => {
							// if(dbKey === "charging_standard"){
							// 	this.form['charging_rules'] = form[dbKey];
							// 	this.disabledObj['charging_rules_isDisabled'] = true;
							// };
							if(key === dbKey){
								this.disabledObj[key+'_isDisabled'] = true;
								this.form[key] = form[dbKey]
							}
							if(dbKey === "source_table"){
								this.form['source_table'] = form[dbKey];
							}
							if(dbKey === "source_id"){
								this.form['source_id'] = form[dbKey];
							}
							if(dbKey === "source_user_id"){
								this.form['source_user_id'] = form[dbKey];
							}
						})
					})
				}
														        if (this.form["invitation_time"] && JSON.stringify(this.form["invitation_time"]).indexOf("-")===-1){
            this.form["invitation_time"] = this.$toTime(parseInt(this.form["invitation_time"]),"yyyy-MM-dd hh:mm:ss")
        }
						$.db.del("form");

				return param;
			},

			/**
			 * 获取对象之后
			 * @param {Object} json
			 * @param {Object} func
			 */
			get_obj_after(json, func){
																																																																						if(this.form["invitation_time"]=="0000-00-00 00:00:00"){
				  this.form["invitation_time"] = null;
				}
				if(parseInt(this.form["invitation_time"]) > 9999){
					this.form["invitation_time"] = this.$toTime(parseInt(this.form["invitation_time"]),"yyyy-MM-dd hh:mm:ss")
				}
										

			},

																																																																																																																					async submit(param, func){
				if (!param) {
					param = this.form;
				}
						
				var pm = this.events("submit_before", Object.assign({}, param)) || param;
				var msg = await this.events("submit_check", pm);
				var ret;
				if (msg) {
					this.$toast(msg, 'danger');
				} else {
																																																																																																																				ret = this.events("submit_main", pm, func);
				}
				return ret;
			},
			
			/**
			 * 提交前验证事件
			 * @param {Object} 请求参数
			 * @return {String} 验证成功返回null, 失败返回错误提示
			 */
						submit_check(param) {
					
																																																																																																																																																						if (!param.invitation_time){
					return "邀请时间不能为空";
				}
																											return null;
			},

			is_view(){
				// var bl = this.user_group == "管理员";
				var bl = false;

				if(!bl){
					bl = this.$check_action('/interview_invitation/table','add');
					console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
				}
				if(!bl){
					bl = this.$check_action('/interview_invitation/table','set');
					console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
				}
				if(!bl){
					bl = this.$check_action('/interview_invitation/view','add');
					console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
				}
				if(!bl){
					bl = this.$check_action('/interview_invitation/view','set');
					console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
				}
				if(!bl){
					bl = this.$check_action('/interview_invitation/view','get');
					console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
				}

				console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

				return bl;
			},
			/**
			 * 上传文件
			 * @param {Object} param
			 */
			uploadimg(param) {
				this.uploadFile(param.file, "avatar");
			},

		},
		created() {
					this.get_list_user_enterprise_user();
																						this.get_list_user_ordinary_user();
																	},
	}
</script>

<style>
	.avatar-uploader .el-upload {
		border: 1px dashed #d9d9d9;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}

	.avatar-uploader .el-upload:hover {
		border-color: #409EFF;
	}

	.avatar-uploader-icon {
		font-size: 28px;
		color: #8c939d;
		width: 178px;
		height: 178px;
		line-height: 178px;
		text-align: center;
	}

	.avatar {
		width: 178px;
		height: 178px;
		display: block;
	}
	
	.img_multiple{
		overflow: hidden;
	}
	.img_multiple .img_block{
		float: left;
		margin-right: 5px;
		margin-bottom: 5px;
		position: relative;
	}
	.img_multiple .img_block img{
		height: 100px;
		width: auto;
	}
	.img_multiple .img_del{
		position: absolute;
		top: 5px;
		right: 5px;
		width: 20px;
		height: 20px;
		background: #0000008a;
		color: #fff;
		line-height: 20px;
		text-align: center;
		border-radius: 100%;
		cursor: pointer;
	}




	
</style>
